using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

using EntLibEC.Biz.RMA;

using EntLibEC.Cmn;


namespace EntLibEC.View.Report
{
	/// <summary>
	/// Summary description for RMAInventoryReport.
	/// </summary>
	public partial class RMAInventoryReport : PageBase
	{
		protected EntLibEC.View.Cmn.StockProduct ucProduct ;
	
		protected void Page_Load(object sender, System.EventArgs e)
		{
		
		}

		private void bindGrid()
		{
			Hashtable ht = new Hashtable();
			if(ucProduct.ProductSysNo != AppConst.IntNull)
				ht.Add("ProductSysNo" , ucProduct.ProductSysNo);
		    DataSet ds = RMARegisterManager.GetInstance().SearchRMAStore(ht);
			int count = 0;
			if(Util.HasMoreRow(ds))
			{
				count = ds.Tables[0].Rows.Count;
			}			
			dgRMAInventory.DataSource = convertDs(ds);
			dgRMAInventory.DataBind();
			Assert(lblMessage , count.ToString() + " record(s)" , 1);
		}

		private DataSet convertDs(DataSet ds)
		{
		    if(!Util.HasMoreRow(ds))
				return ds;

			ds.Tables[0].Columns.Add("left");

			foreach(DataRow dr in ds.Tables[0].Rows)
			{
			    dr["left"] = Util.TrimIntNull(dr["total"]) - Util.TrimIntNull(dr["outbounded"]) - Util.TrimIntNull(dr["reverted"]) - Util.TrimIntNull(dr["returned"]);
			}

			return ds;
		}


		#region Web Form Designer generated code
		override protected void OnInit(EventArgs e)
		{
			//
			// CODEGEN: This call is required by the ASP.NET Web Form Designer.
			//
			InitializeComponent();
			base.OnInit(e);
		}
		
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{    

		}
		#endregion

		protected void btnSearch_Click(object sender, System.EventArgs e)
		{
			bindGrid();
		}
	}
}
